$('#addSKU').click(function () {
    var attrId = $('#skuSelect').val();
    var attrName = $('#skuSelect option:selected').text();

    if (attrId == null) {
        return false;
    }

    $('#skuList').append(
            '<li>\n\
                <span>' + attrName + '</span>\n\
                <input type="hidden" name="attrs[id][]" class="id" value="' + attrId + '" /> \n\
                <input type="text" name="attrs[sort][]" placeholder="排序" class="sort" /> \n\
                <input type="hidden" name="attrs[group][]" /> \n\
                <a href="javascript:void(0);" onclick="del(this,\'skuSelect\');">删除</a>\n\
                </li>'
            );
    $('#skuSelect option[value=' + attrId + ']').remove();
});

$('#addSPEC').click(function () {
    var attrId = $('#specSelect').val();
    var attrName = $('#specSelect option:selected').text();

    if (attrId == null) {
        return false;
    }

    $('#specList').append(
            '<li>\n\
                <span>' + attrName + '</span>\n\
                <input type="hidden" name="attrs[id][]" class="id" value="' + attrId + '" /> \n\
                <input type="text" name="attrs[sort][]" value="" placeholder="排序" class="sort" /> \n\
                <input type="text" name="attrs[group][]" value="" placeholder="分组名" class="group" /> \n\
                <a href="javascript:void(0);" onclick="del(this,\'specSelect\');">删除</a>\n\
                </li>'
            );
    $('#specSelect option[value=' + attrId + ']').remove();
});

function del(e, select) {
    var e=$(e).parent();
    var name=$(e).find('span').html();
    var id=$(e).find('input.id').val();
    
    $(e).remove();
    $('#'+select).append('<option value="'+id+'">'+name+'</option>');
}